package com.meng.mengui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by meng on 2017/10/7.
 */

public class MainAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<String> titleList;
    private List<Integer> imgList;

    public MainAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setData(List<String> list, List<Integer> img) {
        titleList=list;
        imgList=img;
    }

    @Override
    public int getCount() {
        return titleList.size();
    }

    @Override
    public Object getItem(int i) {
        return titleList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_ict_grid, null);
            holder = new ViewHolder();
           holder.img = (ImageView) convertView.findViewById(R.id.img);
           holder.title = (TextView) convertView.findViewById(R.id.title);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.img.setImageResource(imgList.get(position));
        holder.title.setText(titleList.get(position));
        return convertView;
    }

    private class ViewHolder {
        private ImageView img;
        TextView title;


    }
}
